import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import set_node_cls from "@dfeidao/atom-web/ui/set-node-cls";
import set_nodes_cls from "@dfeidao/atom-web/ui/set-nodes-cls";

import set from '@dfeidao/atom-web/local/set';

import render from '@dfeidao/atom-web/render/render';
import p002 from './p002';
import p003 from './p003';
import p004 from './p004';
import p005 from './p005';

export default async function a003(fd: IFeidaoAiBrowserComponent, e: Event) {


	const n = e.currentTarget as HTMLDivElement;
	const nodes = fd.data.node.querySelectorAll<HTMLDivElement>('[data-ids="www"]');
	const nds = Array.from(nodes) as HTMLElement[];
	set_nodes_cls(nds, 'w-bg-themef', true);// 移除所有选中
	set_node_cls(n, 'w-bg-themef', false);// 添加单个选中
	const no = n.getAttribute('data-no');// 编号
	const name = n.getAttribute('data-name');// 名称



	const ne = n.getAttribute('data-no');
	const id = n.getAttribute('data-id');
	const risk_po_type_name_a = n.getAttribute('data-name');
	const risk_level = n.getAttribute('data-dj');

	console.log("这是啥===》", ne);
	console.log("这是啥===》", id);

	let risk_po_type_name = risk_po_type_name_a;
	if (!risk_po_type_name) {
		const nodes = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-actions="click:a003"]');
		risk_po_type_name = nodes.getAttribute('data-name');

		console.log("sddddsdsd", risk_po_type_name);
	}


	let canshu = { id, risk_po_type_name, risk_level, ne };
	set(fd, 'canshu', canshu);

	console.log("非风险=>", canshu);

	render(fd, canshu, p004, 'p004', 'inner');

	// 查询风险点数据
	const pn = fd.data.params['page-no'] as string;
	let pno = 1;
	if (pn) {
		pno = parseInt(pn, 10);
	}

	console.log(pno);




	const res = await nodejs<{ res: Array<{}>; c: number; }>('risk_point/zj-000001/s003', { page_no: pno, risk_po_type_no: ne });

	console.info("youwushuju =>", res);


	const p2 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const p3 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');

	const p5 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p005"]');
	if (res.res.length > 0) {
		render(fd, res.res, p002, 'p002', 'inner');
		render(fd, res.c, p003, 'p003', 'inner');
		render(fd, canshu, p004, 'p004', 'inner');

		set_node_cls(p2, 'display-n', false);
		set_node_cls(p3, 'display-n', false);
		set_node_cls(p5, 'display-n', true);
	} else {
		render(fd, '', p005, 'p005', 'inner');

		set_node_cls(p2, 'display-n', true);
		set_node_cls(p3, 'display-n', true);
		set_node_cls(p5, 'display-n', false);
	}


}
